package javase.ch05.homeWork.Demo3;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.net.Socket;
import java.util.Scanner;
import java.util.concurrent.CountDownLatch;

public class WriterThread implements Runnable{
    Socket socket;
    private CountDownLatch countDownLatch;
    public WriterThread(Socket socket, CountDownLatch countDownLatch){
        this.socket = socket;
        this.countDownLatch = countDownLatch;
    }
    @Override
    public void run() {

        try(
              Scanner sc =  new Scanner(System.in);
              PrintWriter out = new PrintWriter(socket.getOutputStream());

        ){
            while(true){
                System.out.println("请说：");
                String message = sc.nextLine();
                out.println(message);
                out.flush();

                if(message.equals("886")){
                    break;
                }
            }

        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            countDownLatch.countDown();
        }
    }
}
